// JeolDlg.h : header file

#pragma once
#include "Globals.h"
#include "Preview.h"
#include "CachedQueue.h"
#include "StateMachine.h"
#include "JeolSource.h"
#include "AdcDevice.h"
#include "AdcDump.h"
#include "Resample.h"

class CJeolDlg : public CDialog, public IDataReceiver
{
private:

	CHeapPtr<IJeolSource> m_pSource;
	CCachedQueue<CFrame> m_queue;
	CResample            m_resampler;
	CTime                m_timeFrame;
	ULONG_PTR m_nTimerID;


public:

	CJeolDlg(CWnd* pParent = NULL);	// standard constructor
	enum { IDD = IDD_JEOLSCANVIEWER_DIALOG };

protected:

	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support

public: // IDataReceiver

	virtual void ReadData(SHORT * pData, SIZE_T nLen);

public:

	void OnFrameStart(void);
	void OnFrameStop(void);
	void OnLineStart(ULONG64 y);
	void OnLineDrop(ULONG64 y);
	void OnLineStop(ULONG64 y);
	void OnPixel(ULONG64 x, ULONG64 y, const CCachedQueue<CFrame> & queue);

private:

	typedef CStateMachine < CJeolDlg, 
		&CJeolDlg::OnFrameStart, 
		&CJeolDlg::OnFrameStop, 
		&CJeolDlg::OnLineStart, 
		&CJeolDlg::OnLineDrop, 
		&CJeolDlg::OnLineStop, 
		&CJeolDlg::OnPixel
	> CFSM;
	
	
	CFSM m_fsm;

protected:
	HICON m_hIcon;
	CPreview m_wndPreview;

	// Generated message map functions
	DECLARE_MESSAGE_MAP()

	virtual BOOL OnInitDialog(void);
	virtual void OnOK(void);
	virtual void OnCancel(void);

	afx_msg void OnClose(void);
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint(void);
	afx_msg HCURSOR OnQueryDragIcon(void);

public:
	afx_msg void OnBnClickedButtonSave();

	afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg void OnBnClickedLogButton();
};
